package com.ryskoo.permission.permission.repository;

import com.ryskoo.framework.core.repository.BasicJPAImpl;
import com.ryskoo.permission.permission.domain.PermissionPO;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class PermissionJPAImpl extends BasicJPAImpl<PermissionPO> implements IPermissionRepository {

	@Override
	public List<PermissionPO> getPermissionByRoleId(String roleId) {
		String sql = "select permission.* from PMS_PERMISSION permission left join PMS_ROLE_PERMISSION_REL rel on permission.uuid = rel.permission_id where rel.role_id = :roleId";
		Query query = this.getH4Session().createSQLQuery(sql).addEntity(PermissionPO.class);
		query.setString("roleId", roleId);
		return query.list();
	}

	/**
	 * 初始化权限,根据角色获取权限列表，放入缓存
	 * 后台管理员和商户登录时，根据登录角色，缓存获取权限
	 * @return
	 */
	@Override
	public void initPermission() {
	}
}
